//
// Created by Joy on 2024/7/24.
//
#define MAXSIZE 100
#include "string.h"
#include "iostream"
using namespace std;


int BF(const char*s,const char *t){
    int i = 0;
    int j = 0;
    int sLen = strlen(s);
    int tLen = strlen(t);
    while (i <= sLen - tLen){
        j = 0;
        while (j < tLen){
            if (t[j] != s[i + j]){
                break;
            }
            j++;
        }
        if (j == tLen){
            return i;
        }
        i++;
    }
    return -1;
}
int BF_2(char *s,char *t,int post){
    int i = post;
    int j = 0;
    while (i < strlen(s) && j < strlen(t)){
        if (t[j] == s[i]){
            j++;i++;
        } else{
            i = i - j + 1;
            j = 0;
        }
    }
    if (j = strlen(t)){
        return i - strlen(t);
    } else{
        return -1;
    }
}

int main(){
    char a[12] = "aabbccddaba";
    char b[4] = "aba";
    int index = BF(a,b);
    cout << index <<endl;
    int result = BF_2(a,b,0);
    cout << result << endl;
    return 0;
}